package com.ruoyi.web.controller.admin.requirement;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.CustomerRequirementRecord;
import com.ruoyi.system.service.ICustomerRequirementRecordService;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户需求Controller
 * 
 * @author ruoyi
 */
@Slf4j
@RestController
@RequestMapping("/admin/requirement/customer")
public class CustomerRequirementController extends BaseController {

    @Autowired
    private ICustomerRequirementRecordService customerRequirementRecordService;

    

    /**
     * 提交/保存项目客户需求记录（按模板项）
     */
    @PostMapping("/record/{projectId}/{projectNo}")
    @ApiOperation("保存项目客户需求记录（按模板项）")
    public AjaxResult saveProjectRequirementRecords(@PathVariable("projectId") Long projectId,
                                                    @PathVariable("projectNo") String projectNo,
                                                    @RequestBody List<CustomerRequirementRecord> records) {
        Long designerId = getUserId();
        String designerName = getUsername();
//        Long designerId = 1L;
//        String designerName = "getUsername()";
        customerRequirementRecordService.saveOrUpdateRecords(projectId, projectNo, designerId, designerName, records);
        return AjaxResult.success();
    }

    /**
     * 查询项目客户需求记录
     */
    @GetMapping("/record/{projectId}")
    @ApiOperation("查询项目客户需求记录")
    public AjaxResult listProjectRequirementRecords(@PathVariable("projectId") Long projectId) {
        List<CustomerRequirementRecord> list = customerRequirementRecordService.listByProjectId(projectId);
        return AjaxResult.success(list);
    }
}
